


var _iValueOld;
var _bIsAttribute;
var _aValues;
var _iValues;
var _bIsCustomAttribute;

function ListValueJsWindowOnLoad()
{
_bIsAttribute = window.dialogArguments.bIsAttribute;
var iValue = window.dialogArguments.iValue;
if(_bIsAttribute && window.dialogArguments.sAttributeType == "picklist")
{
_aValues = window.dialogArguments.aValues;
numValue.max = maxValueForPicklists;
if(window.dialogArguments.isCustomAttribute ==  "False")
{
_bIsCustomAttribute = false;
}
else
{
_bIsCustomAttribute = true;
}

if(mode == "add")
{
if(_bIsCustomAttribute)
{
numValue.min = minValueForCustomPicklists;
}
else
{
numValue.min = minValueForSystemPicklists;
}
_iValues = new Array();

for(var i = 1; i < _aValues.length; i++)
{
_iValues[i-1] = _aValues[i].iValue;
}
_iValues.sort(function(a,b){return a > b});

for(var i = 0; i < _iValues.length; i++)
{
if(iValue == _iValues[i])
{
iValue++;
}
}

}
else
{
if(_bIsCustomAttribute || (window.dialogArguments.iValue < minValueForSystemPicklists))
{
numValue.min = minValueForCustomPicklists;
}
else
{
numValue.min = minValueForSystemPicklists;
}

}
numValue.Disabled = false;
numValue.attachEvent('onblur',ValidateValue );

}
else
{

}
_iValueOld = iValue;
numValue.DataValue = iValue;
txtLabel.DataValue = window.dialogArguments.sLabel;
txtLabel.SetFocus();

}

window.attachEvent('onload', ListValueJsWindowOnLoad);




function cancel()
{
window.close();
}

function applychanges()
{
if(_bIsAttribute  && numValue.DataValue != _iValueOld && mode == "edit")
{
var confirmOptionValueChange = confirm(LOCID_CONFIRM_CHANGE);
if(confirmOptionValueChange)
{

}
else
{
numValue.SetFocus();
return;
}
}

var sLabel = TrimSpaces(txtLabel.DataValue);

if (sLabel == null || sLabel.length <= 0)
{
alert(LOCID_NOLABEL);

txtLabel.SetFocus();

return;
}

var oResult = new Object();

oResult.iValue = numValue.DataValue;
oResult.sLabel = sLabel;

window.returnValue = oResult;

window.close();
}



function ValidateValue()
{
if(numValue.DataValue == _iValueOld)
{
return;
}
if(!_bIsCustomAttribute && numValue.DataValue < minValueForSystemPicklists)
{
var outOfRangeError = formatString(LOCID_PICKLIST_RANGE, numValue.DataValue);
numValue.SetFocus();
numValue.DataValue = _iValueOld;
alert(outOfRangeError);
return;
}
CheckIfValueIsUnique();

}


function CheckIfValueIsUnique()
{
for (var i = 1; i < _aValues.length; i++)
{
if(numValue.DataValue == _aValues[i].iValue)
{
var valueNotUniqueError = formatString(LOCID_VALUE_NOT_UNIQUE, _aValues[i].iValue, _aValues[i].sLabel);
alert(valueNotUniqueError);
numValue.DataValue = _iValueOld;
numValue.SetFocus();
return;
}
}

}

